# encoding: utf-8

class Admin::SettingsController < ApplicationController
  def index
    @settings = Setting.find(:all)
    @page_title = 'Listing settings'
  end

  def new
    @setting = Setting.new
    @page_title = 'Create new setting'
  end

  def create    
    @setting = Setting.new(params[:setting])
    if @setting.save
      flash[:notice] = "Setting #{@setting.name} was successfully created."
    redirect_to :action => 'index'
    else
      @page_title = 'Create new setting'
      render :action => 'new'
    end
  end

  def edit
    @setting = Setting.find(params[:id])
    @page_title = 'Edit setting'
  end

  def destroy
    @setting = Setting.find(params[:id])
    flash[:notice] = "Successfully deleted setting #{@setting.name}"
    @setting.destroy
    redirect_to :action => 'index'
  end

  def update
    @setting = Setting.find(params[:id])
    if @setting.update_attributes(params[:setting])
      flash[:notice] = "Setting #{@setting.name} was successfully updated."
    redirect_to :action => 'show', :id => @setting.id
    else
      @page_title = 'Edit setting'
      render :action => 'edit'
    end
  end
  
  def show
    @setting = Setting.find(params[:id])
    @page_title = @setting.name
  end

end
